/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FieldDialogPane.java
 *
 * Created on 03-ene-2010, 0:21:58
 */

package geobloc.desktop.dialogs;

import java.util.Vector;

/**
 *
 * @author Usuario
 */
public class FieldDialogPane extends javax.swing.JPanel {

    /** Creates new form FieldDialogPane */
    public FieldDialogPane() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        typesButtonGroup = new javax.swing.ButtonGroup();
        labelLabel = new javax.swing.JLabel();
        labelTextField = new javax.swing.JTextField();
        typeLabel = new javax.swing.JLabel();
        stringTypeButton = new javax.swing.JRadioButton();
        integerTypeButton = new javax.swing.JRadioButton();
        floatTypeButton = new javax.swing.JRadioButton();
        linesLabel = new javax.swing.JLabel();
        linesSpinner = new javax.swing.JSpinner();
        requiredCheckBox = new javax.swing.JCheckBox();
        idLabel = new javax.swing.JLabel();
        idTextField = new javax.swing.JTextField();
        descriptionLabel = new javax.swing.JLabel();
        descriptionScrollPane = new javax.swing.JScrollPane();
        descriptionTextArea = new javax.swing.JTextArea();
        defaultValueLabel = new javax.swing.JLabel();
        defaultValueScrollPane = new javax.swing.JScrollPane();
        defaultValueTextArea = new javax.swing.JTextArea();

        setName("FieldDialog"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(geobloc.desktop.FormDesignerApp.class).getContext().getResourceMap(FieldDialogPane.class);
        labelLabel.setText(resourceMap.getString("labelLabel.text")); // NOI18N
        labelLabel.setName("labelLabel"); // NOI18N

        labelTextField.setText(resourceMap.getString("labelTextField.text")); // NOI18N
        labelTextField.setName("labelTextField"); // NOI18N

        typeLabel.setText(resourceMap.getString("typeLabel.text")); // NOI18N
        typeLabel.setName("typeLabel"); // NOI18N

        typesButtonGroup.add(stringTypeButton);
        stringTypeButton.setSelected(true);
        stringTypeButton.setText(resourceMap.getString("stringTypeButton.text")); // NOI18N
        stringTypeButton.setActionCommand(resourceMap.getString("stringTypeButton.actionCommand")); // NOI18N
        stringTypeButton.setName("stringTypeButton"); // NOI18N

        typesButtonGroup.add(integerTypeButton);
        integerTypeButton.setText(resourceMap.getString("integerTypeButton.text")); // NOI18N
        integerTypeButton.setActionCommand(resourceMap.getString("integerTypeButton.actionCommand")); // NOI18N
        integerTypeButton.setName("integerTypeButton"); // NOI18N

        typesButtonGroup.add(floatTypeButton);
        floatTypeButton.setText(resourceMap.getString("floatTypeButton.text")); // NOI18N
        floatTypeButton.setActionCommand(resourceMap.getString("floatTypeButton.actionCommand")); // NOI18N
        floatTypeButton.setName("floatTypeButton"); // NOI18N

        linesLabel.setText(resourceMap.getString("linesLabel.text")); // NOI18N
        linesLabel.setName("linesLabel"); // NOI18N

        linesSpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 5, 1));
        linesSpinner.setName("linesSpinner"); // NOI18N

        requiredCheckBox.setText(resourceMap.getString("requiredCheckBox.text")); // NOI18N
        requiredCheckBox.setName("requiredCheckBox"); // NOI18N

        idLabel.setText(resourceMap.getString("idLabel.text")); // NOI18N
        idLabel.setName("idLabel"); // NOI18N

        idTextField.setText(resourceMap.getString("idTextField.text")); // NOI18N
        idTextField.setName("idTextField"); // NOI18N

        descriptionLabel.setText(resourceMap.getString("descriptionLabel.text")); // NOI18N
        descriptionLabel.setName("descriptionLabel"); // NOI18N

        descriptionScrollPane.setName("descriptionScrollPane"); // NOI18N

        descriptionTextArea.setColumns(20);
        descriptionTextArea.setFont(resourceMap.getFont("descriptionTextArea.font")); // NOI18N
        descriptionTextArea.setLineWrap(true);
        descriptionTextArea.setRows(3);
        descriptionTextArea.setName("descriptionTextArea"); // NOI18N
        descriptionScrollPane.setViewportView(descriptionTextArea);

        defaultValueLabel.setText(resourceMap.getString("defaultValueLabel.text")); // NOI18N
        defaultValueLabel.setName("defaultValueLabel"); // NOI18N

        defaultValueScrollPane.setName("defaultValueScrollPane"); // NOI18N

        defaultValueTextArea.setColumns(20);
        defaultValueTextArea.setFont(resourceMap.getFont("defaultValueTextArea.font")); // NOI18N
        defaultValueTextArea.setLineWrap(true);
        defaultValueTextArea.setRows(2);
        defaultValueTextArea.setName("defaultValueTextArea"); // NOI18N
        defaultValueScrollPane.setViewportView(defaultValueTextArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(defaultValueLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 173, Short.MAX_VALUE)
                .addComponent(requiredCheckBox))
            .addGroup(layout.createSequentialGroup()
                .addComponent(labelLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(idLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(typeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(stringTypeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(integerTypeButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(floatTypeButton)
                .addGap(18, 18, 18)
                .addComponent(linesLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(linesSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(descriptionLabel)
            .addComponent(defaultValueScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
            .addComponent(descriptionScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelLabel)
                    .addComponent(labelTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(idLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(typeLabel)
                    .addComponent(stringTypeButton)
                    .addComponent(integerTypeButton)
                    .addComponent(floatTypeButton)
                    .addComponent(linesLabel)
                    .addComponent(linesSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(defaultValueLabel)
                    .addComponent(requiredCheckBox))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(defaultValueScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(descriptionLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    /* Public method for retriving the user input data from the dialog
     * params[0] - ID
     * params[1] - Description
     * params[2] - Field label
     * params[3] - Field default value
     * params[4] - Field type
     * params[5] - Field lines number
     * params[6] - Is required
     */
    public Vector<String> getResults() {
        Vector<String> parameters = new Vector<String>();
        // Add the element ID
        parameters.add(idTextField.getText());
        // Add the description or null if it wasn't written
        if (descriptionTextArea.getText().isEmpty())
            parameters.add(null);
        else
            parameters.add(descriptionTextArea.getText());
        // Add the field label
        parameters.add(labelTextField.getText());
        // Add the default value
        parameters.add(defaultValueTextArea.getText());
        // Add the field type
        parameters.add(typesButtonGroup.getSelection().getActionCommand());
        // Add the field lines number
        parameters.add(linesSpinner.getValue().toString());
        // Add the is required checkbox value
        if (requiredCheckBox.isSelected())
            parameters.add("true");
        else
            parameters.add("false");
        return parameters;
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel defaultValueLabel;
    private javax.swing.JScrollPane defaultValueScrollPane;
    private javax.swing.JTextArea defaultValueTextArea;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JScrollPane descriptionScrollPane;
    private javax.swing.JTextArea descriptionTextArea;
    private javax.swing.JRadioButton floatTypeButton;
    private javax.swing.JLabel idLabel;
    private javax.swing.JTextField idTextField;
    private javax.swing.JRadioButton integerTypeButton;
    private javax.swing.JLabel labelLabel;
    private javax.swing.JTextField labelTextField;
    private javax.swing.JLabel linesLabel;
    private javax.swing.JSpinner linesSpinner;
    private javax.swing.JCheckBox requiredCheckBox;
    private javax.swing.JRadioButton stringTypeButton;
    private javax.swing.JLabel typeLabel;
    private javax.swing.ButtonGroup typesButtonGroup;
    // End of variables declaration//GEN-END:variables

}
